//
//  SDSelecterCaseTableViewCell.m
//  SuperDoctor
//
//  Created by 林森 on 16/7/7.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDSelecterCaseTableViewCell.h"
#import "SDCollectionView.h"

@interface SDSelecterCaseTableViewCell ()<UITextViewDelegate>

@property (nonatomic,weak)UIButton * button;
@property (nonatomic,weak)UITextView * text;
@property (nonatomic,weak)UILabel * lb_label;
@property (nonatomic,weak)SDCollectionView * collection;
@property (nonatomic,strong)UICollectionViewFlowLayout * flowlayout;

@end

@implementation SDSelecterCaseTableViewCell

//MARK: - 自定义cell创建调用方法,根据不同的传递不同的值加载不同的cell
- (instancetype)newCellSelecter:(BOOL)numBool caseModel:(SDCaseManageModel *)caseModel{
    
    SDSelecterCaseTableViewCell * sele = [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
    sele.caseManGeModel = caseModel;
    
    [self showCell:numBool];
    
    
    return sele;
}

#pragma mark - cell的子控件创建
-(void)showCell:(BOOL)onBool{
    
    //MARK: - 两个cell都有的label
    UILabel * label = [[UILabel alloc]init];
    
    self.lb_label = label;
    
    [self.contentView addSubview:label];
    
    if (onBool) {
        //MARK: - 根据布尔值加载文本view和label的文本
        UITextView * text = [[UITextView alloc]init];
        
        text.delegate = self;
        
        _text =text;
        
        text.backgroundColor = [UIColor grayColor];
        
        [self.contentView addSubview:text];
        
        label.text=@"病症描述:";
        
    }else{
        //MARK: - 根据布尔值加载添加图片按钮和label的文本
        
        label.text=@"病例照片:";
        
        UICollectionViewFlowLayout * flowlalyout = [[UICollectionViewFlowLayout alloc]init];
        
        _flowlayout = flowlalyout;
        
        flowlalyout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        
        flowlalyout.itemSize = CGSizeMake((self.bounds.size.width)/(4), 100);
        
        SDCollectionView * collection = [[SDCollectionView alloc] newCollecttionView:flowlalyout array:self.caseManGeModel.array];
    
        [self.contentView addSubview:collection];
        
        self.collection = collection;
        
        self.collection.backgroundColor = [UIColor whiteColor];
        
        
    }
    
    [self layoutCellSubView];
    
}

#pragma mark - 布局子控件方法
- (void)layoutCellSubView{
    
    [_lb_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
    }];
    
    [_text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lb_label.mas_bottom).offset(10);
        make.height.offset(100);
        make.leading.offset(10);
        make.bottom.trailing.offset(-10);
    }];
    [_collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lb_label.mas_bottom).offset(10);
        make.height.offset(100);
        make.leading.offset(10);
        make.bottom.trailing.offset(-10);
    }];
    
    
}



#pragma mark - textView编辑时调用
- (void)textViewDidChange:(UITextView *)textView{
    
    
    self.caseManGeModel.describe = textView.text;
    
}

- (void)setCaseManGeModel:(SDCaseManageModel *)caseManGeModel{
    
    _caseManGeModel = caseManGeModel;
    
    if (caseManGeModel.imageIC != nil) {
        
        [_button setImage:caseManGeModel.imageIC forState:UIControlStateNormal];
    }
    self.text.text = caseManGeModel.describe;
    
    
}

- (void)clickAddImage{
    
    _imgBlock();
        
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated{

}

@end
